#include <iostream>
#include <list>
using namespace std;
 
void show_list(list<int> L)
{ list<int>::iterator p;
  for(p=L.begin(); p!=L.end(); p++)
    cout << *p << " ";
  cout << endl;
}    
  
int a[5] = {32,45,12,24,29};
list<int> L(a,a+5);

int main()
{ 
  show_list(L);
  
  L.push_front(50);
  L.push_front(40);
  L.push_back(56);  
  L.push_front(34);
  L.push_back(45);
  L.push_front(30);
  L.push_front(20);
  
  show_list(L);
  
  list<int>::iterator p = L.begin();
  for(int i=1; i<=4; i++) p++;

  list<int>::iterator q = L.end();
  for(int i=1; i<=3; i++) q--;
  
  cout << *p << " " << *q << endl;
   
  L.erase(p,q);
  show_list(L);
    
     
  return 0;
}    
